import Vue from "vue";
import  search from "@/api/search";
import  router from "@/router";
export const handleBatchSearch = (context,pageNo=1,pageSize=12) => {
  // context.state.batchSearchForm
  if (!context.state.batchSearchForm.type) { 
    Vue.prototype.$message({
      message: "Select search words!",
      type: "warning",
    });
    return;
  }
  if (context.state.batchSearchForm.gene) {
    search
      .batchSearchCategoryInfo({
        name: context.state.batchSearchForm.gene.split(",") + "",
        pageNo,
        pageSize,
        type: context.state.batchSearchForm.type,
      })
      .then((res) => {
        context.commit("set_batchTableData", res);
        router.originalPush({
          path: "/searchBatchResult",
        });
      });
  } else {
    if (!context.state.batchSearchForm.file) {
      Vue.prototype.$message({
        message: "Input a gene or upload file!",
        type: "warning",
      });
      return;
    }
    let formData = new FormData();
    formData.append("file", context.state.batchSearchForm.file);
    formData.append("type", context.state.batchSearchForm.type);
    formData.append("pageNo", pageNo);
    formData.append("pageSize", pageSize);
    search.batchSearchCategoryInfoByFile(formData).then((res) => {
      context.commit("set_batchTableData", res);
      router.originalPush({
        path: "/searchBatchResult",
      });
    });
  }
};
